package com.itheima.day09work.empservice.impl;

import com.itheima.day09work.empservice.EmpService;
import com.itheima.day09work.mapper.EmpMapper;
import com.itheima.day09work.pojo.Emp;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    private final EmpMapper empmapper;

    static  List<Emp> emplist;

    public EmpServiceImpl(EmpMapper empmapper) {
        this.empmapper = empmapper;
    }
    //1.添加一个学生
    @Override
    public void saveOne(Emp emp) {
    emp.setCreateTime(LocalDateTime.now());
    emp.setUpdateTime(LocalDateTime.now());
    empmapper.insertOne(emp);
    }
    //删除一个学生
    @Override
    public void removeById(String id) {
    int intId = Integer.parseInt(id);
    empmapper.deleteOne(intId);
    }
    //更新一个学生
    @Override
    public void updateById(Emp emp) {
    //int id = emp.getId();
    empmapper.updateOne(emp);
    }
    //查询所有学生
    @Override
    public List<Emp> queryList() {
        emplist = empmapper.selectAllEmp();
        return emplist;
    }
    //根据id查找一个学生
    @Override
    public Emp queryById(String id) {
        Emp emp = empmapper.selectById(id);
        return emp;
    }
}
